1. Field of the Invention
The present invention relates to optimized multiprocessing in a safe language, and in particular to an optimizing, backward-compatible, compiler-linker-run time architecture for multiprocessing in a safe language, such as Java.
Portions of the disclosure of this patent document contain material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the Patent and Trademark Office file or records, but otherwise reserves all copyright rights whatsoever.
2. Background Art
With advancements in network technology, the use of networks for facilitating the, distribution of media information, such as text, graphics, and audio, has grown dramatically, particularly in the case of the Internet and the World Wide Web. One area of focus for current developmental efforts is in the field of multiprocessing of web applications. In addition to passive media content, such as HTML definitions, computer users or xe2x80x9cclientsxe2x80x9d coupled to the network are able to access or download application content, in the form of applets, for example, from xe2x80x9cserversxe2x80x9d on the network.
To accommodate the variety of hardware systems used by clients, applications or applets are distributed in a platform-independent format such as the Java.RTM. class file format. Object-oriented applications are formed from multiple class files that are accessed from servers and downloaded individually as needed. Class files contain bytecode instructions. A xe2x80x9cvirtual machinexe2x80x9d process that executes on a specific hardware platform loads the individual class files and executes the bytecodes contained within.
In U.S. patent application entitled xe2x80x9cSmall memory footprint system and method for separating applications within single virtual machine,xe2x80x9d Ser. No. 09/513,291 filed on Feb. 25, 2000, Sun Microsystem assigned to the assignee of the present application, and hereby fully incorporated into the present application by reference, a method for optimized Java multiprocessing is described. In that invention, one is able to run multiple Java applications in the same Java virtual machine and introduce optimizations at load time and run time.
A Java program is composed of a number of classes and interfaces. Unlike many programming languages, in which a program is compiled into machine-dependent, executable program code, Java classes are compiled into machine independent bytecode class files. Each class contains code and data in a platform-independent format called the class file format. The computer system acting as the execution vehicle contains a program called a virtual machine, which is responsible for executing the code in Java classes. The virtual machine provides a level of abstraction between the machine independence of the bytecode classes and the machine-dependent instruction set of the underlying computer hardware. Hence, Java provides an example of a safe language.
A xe2x80x9cclass loaderxe2x80x9d within the virtual machine is responsible for loading the bytecode class files as needed, and either an interpreter executes the bytecodes directly, or a xe2x80x9cjust-in-timexe2x80x9d (JIT) compiler transforms the bytecodes into machine code, so that they can be executed by the processor. FIG. 1 is a block diagram illustrating a sample Java network environment comprising a client platform 102 coupled over a network 101 to a server 100 for the purpose of accessing Java class files for execution of a Java application or applet.
In FIG. 1, server 100 comprises Java development environment 104 for use in creating the Java class files for a given application. The Java development environment 104 provides a mechanism, such as an editor and an applet viewer, for generating class files and previewing applets. A set of Java core classes 103 comprise a library of Java classes that can be referenced by source files containing other/new Java classes. From Java development environment 104, one or more Java source files 105 are generated. Java source files 105 contain the programmer readable class definitions, including data structures, method implementations and references to other classes. Java source files 105 are provided to Java compiler 106, which compiles Java source files 105 into compiled xe2x80x9cclassxe2x80x9d files 107 that contain bytecodes executable by a Java virtual machine. Bytecode class files 107 are stored (e.g., in temporary or permanent storage) on server 100, and are available for download over network 101.
Client platform 102 contains a Java virtual machine (JVM) 111 which, through the use of available native operating system (O/S) calls 112, is able to execute bytecode class files and execute native O/S calls when necessary during execution.
Java class files are often identified in applet tags within an HTML (hypertext markup language) document. A web server application 108 is executed on server 100 to respond to HTTP (hypertext transport protocol) requests containing URLs (universal resource locators) to HTML documents, also referred to as xe2x80x9cweb pages.xe2x80x9d When a browser application executing on client platform 102 requests an HTML document, such as by forwarding URL 109 to web server 108, the browser automatically initiates the download of the class files 107 identified in the applet tag of the HTML document. Class files 107 are typically downloaded from the server and loaded into virtual machine 111 individually as needed.
It is typical for the classes of a Java program to be loaded as late during the program""s execution as possible; they are loaded on demand from the network (stored on a server), or from a local file system, when first referenced during the Java program""s execution. The virtual machine locates and loads each class file, parses the class file format, allocates memory for the class""s various components, and links the class with other already loaded classes. This process makes the code in the class readily executable by the virtual machine.
In one prior art technique, the system transparently maintains a copy of the static fields for each application. Code for each method is shared among all applications, while static fields for each class are subject to automatic and transparent multiplexing. The effect of this invention is to allow for space efficient isolation among applications, reduced load and compilation times, and making the isolation between applications stronger than what class loader based Java multiprocessing could previously provide.
The above-referenced technique, however, creates problems of its own. Because multiple applications share static fields, concurrency problems arise. For instance, if application A accesses static field 1, and application B also accesses static field 1, the potential arises that application A may modify the data in static field 1, which is undesirable from a perspective of isolation. Application B expects static field 1 to be its own static field and may expect certain values from static field 1. If application A modifies this field, application B will see a modified value and have no understanding as to why it changed.
The above-referenced technique seeks to solve this problem by introducing optimizations at load time and run time which seek to protect such shared static fields in a multiprocessing environment. Optimizations at load time and run time, however, introduce considerable overhead at a time critical point from the user""s perspective, while the less time critical compilation phase remains relatively unaffected. A method and apparatus is needed to target the optimal points in the compiler-loader-run time path to allocate the optimization work.
The present invention provides a method and apparatus for optimized multiprocessing in a safe language by targeting the optimal points in the compiler-loader-run time path to allocate the optimization work. One or more embodiments provide for the optimized execution of multiple processes in a single Java virtual machine. The optimization work allows for the isolation of each of the processes, and the ability to execute each process quickly by shifting the bulk of optimization work from load time and/or run time to compile time.
The invention includes a compiler which analyzes its input source code to detect xe2x80x9cpreservable static fieldsxe2x80x9d. Preservable static fields are defined as those fields containing variables which are certain to not be modified by multiple applications concurrently executing in the same environment. Hence, multiple applications can share the preservable static field without any need for additional overhead to protect the preservable static field from the danger associated with concurrent modification of the field by multiple applications (i.e., the applications will remain isolated from one another).
In one embodiment, preservable static fields are read only objects. In one or more other embodiments, the optimization work of the present invention includes detecting preservable static fields of the following types: (i) static final fields of primitive types; (ii) static final fields of type string; and (iii) immutable static (multidimensional) arrays of primitive types. In another embodiment, only static final fields of primitive types are detected. In another embodiment, a tunable parameter is introduced which allows customized optimization of each application depending on the needs of the user. The optimizations of the present invention significantly reduce the performance overhead associated with executing multiple applications in a single environment, such as a Java virtual machine or other suitable environment.